package com.qf.controller;

import com.qf.entity.City;
import com.qf.feign.CityFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/back")
public class BackCityController {

    @Autowired
    private CityFeign cityFeign;

    /**
     * 跳转到添加页面
     * @return
     */
    @RequestMapping("/toCityAdd")
    public String toCityAdd(){
        return "cityadd";
    }

    /**
     * 添加城市
     * @return
     */
    @RequestMapping("/cityadd")
    public String cityAdd(City city){
        //通过feign调用城市服务添加城市信息
        cityFeign.insertCity(city);
        return "redirect:/back/cityList";
    }

    /**
     * 查询城市列表
     * @return
     */
    @RequestMapping("/cityList")
    public String cityList(Model model){
        //调用Feign获得城市列表
        List<City> cities = cityFeign.queryCityList();
        model.addAttribute("cities", cities);
        return "citylist";
    }
}
